// 杂项
const commonMixin = {
	data(){
		return{
			//tab内容设定
			tabs: [
				{ name: '互动' }, 
				{ name: '签到' }
			],
			//当前tab index
			currentTab: 0,
			//下拉设定
			downOption: {
				use: false, // 是否启用上拉加载; 默认true
				auto: false // 是否在初始化完毕之后自动执行上拉加载的回调; 默认true
			},
			//上划设定
			upOption: {
				use: false,
				// auto: false,
				// onScroll: true
			},
			showInput: false,
			allow: true,
			focus: false,
			input_placeholder: '我要评论...',
			// 是否允许自动下滑
			canScroll: true,
			//播放器全屏标记
			isFullScreen: false,
			// 时钟倒计时时长
			clockTime: 0,
			// 时钟定时器
			clockTimer: '',
			// 是否显示倒计时时钟
			showClock: false
		}
	},
	computed:{
		//出勤小标题dom
		subCheckTitle:function(){
			return len=>{
				return `共<span style='color:${this.theme.danger}'>${len}</span>人出勤`
			}
		},
		//缺勤小标题dom
		subUnCheckTitle:function(){
			return len=>{
				return `共<span style='color:${this.theme.danger}'>${len}</span>人缺勤`
			}
		},
		//文字长度限定
		subText:function(){
			return (val, len)=>{
				if(!val){
					return ''
				}
				return val.length>len?`${val.substring(0, len)}...`:val
			}
		},
		// 上课倒计时文本
		clockStr(){
			if(!this.clockTime || this.clockTime == 0){
				return "00:00"
			}else{
				let min = Math.floor(this.clockTime/60)
				let sec = this.clockTime%60
				return `${min>=10?min:'0'+min}` + ":"+ `${sec>=10?sec:'0'+sec}`;
			}
		}
	},
	onUnload(){
		clearInterval(this.clockTimer);
	},
	methods:{
		//请求推流数据
		getLivePushInfo(id){
			return this.$http.request({
				url: 'api/LivePush/GetLivePushInfo',
				method: 'GET',
				allow:true,
				data:{
					Id:id
				}
			})
		},
		//刷新
		resume() {
			uni.showLoading({
				mask: true,
				title: '加载中...'
			});
			setTimeout(()=>{
				uni.hideLoading();
			}, 3000)
			this.livePlayer.resume();
		},
		// 全屏
		fullScreen() {
			this.livePlayer.requestFullScreen({ direction: 90 });
			this.isFullScreen = true;
		},
		// 退出全屏
		exitFullScreen() {
			this.livePlayer.exitFullScreen({ direction: 90 });
			this.isFullScreen = false;
		},
		//弹出评论框
		goToComment() {
			this.showInput = true;
			this.$nextTick(function(){
				uni.getSystemInfo().then(resp=>{
					switch (resp[1].platform){
						case 'android':
							this.focus = true
							break
						case 'ios':
							setTimeout(()=>{
								this.focus = true
							}, 100)
							break
					}
				})
			})
		},
		blur() {
			this.init_input();
		},
		init_input() {
			this.showInput = false;
			this.focus = false;
		},
		// 滚动到底部
		goBottom(){
			this.canScroll = true
			this.mescroll.scrollTo(99999, 50)
		},
		// 倒计时时钟
		setClock(){
			if(!this.clockTime || this.clockTime == 0){
				this.showClock = false;
			}else{
				this.showClock = true;
				this.clockTimer = setInterval(()=>{
					// 计时完毕， 停止定时
					if(this.clockTime == 0){
						this.showClock = false;
						clearInterval(this.clockTimer);
					}else{
						this.clockTime--;
					}
				}, 1000);
			}
		}
	}
}

export default commonMixin;